package com.advertise.tool;

import java.util.Enumeration;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;

public class ApplicationHelper {
	private static Map<String, Object> session;
	
	private static HttpServletRequest request;
	
	/*
	 * Use the static block code to get the session 
	 */
	
	static{
		if(session == null ){
			ActionContext actionContext =ActionContext.getContext();
			session = actionContext.getSession();
		}
		
		/*if(request==null){
			request = ServletActionContext.getRequest();
		}*/
	}
	
	public static void putSession(String key,Object value){
		if(session == null ){
			ActionContext actionContext =ActionContext.getContext();
			session = actionContext.getSession();
		}
		session.put(key, value);
	}
	
	public static Object getSessionValue(String key){
		if(session == null ){
			ActionContext actionContext =ActionContext.getContext();
			session = actionContext.getSession();
		}
		return session.get(key);
	}
	
	public static String getRequestParam(String paramName){
		if(request == null){
			request = ServletActionContext.getRequest();
			
		}
		System.out.println("request is "+request);
		
		Enumeration<String> params = request.getParameterNames();
		System.out.println("params is ================");
		while(params.hasMoreElements()){
			System.out.println(params.nextElement());
		}
		
		System.out.println("params is ================");
		return request.getParameter(paramName);
	}
	
	
}
